﻿using System;
using System.Collections;
using System.Data;

public partial class Admin_LinhVuc_LinhVucCon : System.Web.UI.Page
{
    Data data = new Data();
 
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            if (Session["admin"].Equals("true") == false)
            {
                Response.Redirect("../Default.aspx");
            }
            else
            {
                if (IsPostBack == false)
                {
                    FillData();
                }
                else
                {
                    Panel1.Visible = true;
                }
                if (Request.QueryString["delete"] != null)
                {
                    data.Delete_Table(Request.QueryString["delete"].Split(';')[1]);
                    btnGetLinhVucCon_Click(null, null);
                }

            }
        }
        catch (Exception ex)
        {
            Response.Redirect("../Default.aspx");
            throw;
        }
      
    }

    private void FillData()
    {
            DataTable table = data.GetTable_By_Name("MucLucPhapLuat");
            comboboxLinhVucCha.DataSource = table;
            comboboxLinhVucCha.DataValueField = "MucPhapLuatName";
            Panel1.Visible = false;
    }

    protected void btnGetLinhVucCon_Click(object sender, EventArgs e)
    {
        DataTable table = data.GetTable_By_Name(comboboxLinhVucCha.SelectedValue);
        table.Columns[0].ColumnName = "ParentID";
        table.Columns[1].ColumnName = "ChildID";
        table.Columns[2].ColumnName = "Name";
        table.Columns[3].ColumnName = "Description";
        DataListYahoo.DataSource = table;
        DataListYahoo.DataBind();
    }
    protected void BtnCancel_Click(object sender, EventArgs e)
    {
        Response.Redirect("Default.aspx");
    }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        btnSave.Enabled = false;
        data.Add_MucPhapLuatCon(txtTenKoDau.Text, txtTenCoDau.Text,comboboxLinhVucCha.SelectedValue, (comboboxLinhVucCha.SelectedIndex + 1).ToString() );
        btnGetLinhVucCon_Click(sender, e);
        btnSave.Enabled = true;
    }
}
